Leadtools.Annotations Namespace > AnnCodecs Class > Save Method : Save(Stream,AnnContainer[],AnnCodecsFormat) Method |
public void Save( Stream stream, AnnContainer[] containers, AnnCodecsFormat format )
'Declaration Public Overloads Sub Save( _ ByVal stream As Stream, _ ByVal containers() As AnnContainer, _ ByVal format As AnnCodecsFormat _ )
'Usage Dim instance As AnnCodecs Dim stream As Stream Dim containers() As AnnContainer Dim format As AnnCodecsFormat instance.Save(stream, containers, format)
public: void Save( Stream^ stream, array<AnnContainer^>^ containers, AnnCodecsFormat format )
This method saves the entire array of AnnContainer to a stream that will contain multipage pages, with each page corresponding to one of the AnnContainer. If stream contains any data, it will be overwritten. If containers contain many AnnContainer, then this method will create the multipage annotation stream much faster than repeated calls to Save(Stream,AnnContainer,AnnCodecsFormat,Int32,AnnCodecsSavePageMode)
This method only supports the AnnCodecsFormat.Xml format. All other AnnCodecsFormat are not supported.
For more information, refer to Annotation Files.
Imports Leadtools Imports Leadtools.Annotations Imports Leadtools.Codecs Imports Leadtools.WinForms Public Sub AnnCodecs_SaveStream2() ' create three annotation containers ' The first container contains a rectangle object Dim container0 As New AnnContainer() Dim rectObj As New AnnRectangleObject() rectObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel) rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel)) rectObj.Brush = Nothing container0.Objects.Add(rectObj) ' The second container contains a line object Dim container1 As New AnnContainer() Dim lineObj As New AnnLineObject() lineObj.StartPoint = New AnnPoint(100, 100, AnnUnit.Pixel) lineObj.EndPoint = New AnnPoint(200, 200, AnnUnit.Pixel) lineObj.Pen = New AnnPen(Color.Red, New AnnLength(1, AnnUnit.Pixel)) container1.Objects.Add(lineObj) ' The third container contains a ellipse object Dim container2 As New AnnContainer() Dim ellipseObj As New AnnEllipseObject() ellipseObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel) ellipseObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel)) ellipseObj.Brush = Nothing container2.Objects.Add(ellipseObj) ' create a memory stream to save both annotation containers Using ms As New MemoryStream() ' create a new AnnCodecs class Dim codecs As New AnnCodecs() ' save both AnnContainers into the stream codecs.Save(ms, container0, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite) ms.Seek(0, SeekOrigin.Begin) codecs.Save(ms, container1, AnnCodecsFormat.Xml, 2, AnnCodecsSavePageMode.Insert) ms.Seek(0, SeekOrigin.Begin) ' Now load both containers from the stream, and verify that there are two containers Dim containersTwo() As AnnContainer = codecs.Load(ms) MessageBox.Show(String.Format("After Load: there should be 2 containers. Total number of containers: {0}", containersTwo.Length)) ' Add another container, and save to the stream Dim containersNew(containersTwo.Length) As AnnContainer Array.Copy(containersTwo, containersNew, containersTwo.Length) containersNew(2) = container2 ms.Seek(0, SeekOrigin.Begin) codecs.Save(ms, containersNew, AnnCodecsFormat.Xml) ms.Seek(0, SeekOrigin.Begin) ' Load and verify that there are three containers Dim containersThree() As AnnContainer = codecs.Load(ms) MessageBox.Show(String.Format("After Load: there should be 3 containers. Total number of containers: {0}", containersThree.Length)) End Using End Sub
using Leadtools; using Leadtools.Annotations; using Leadtools.Codecs; using Leadtools.WinForms; public void AnnCodecs_SaveStream2() { // create three annotation containers // The first container contains a rectangle object AnnContainer container0 = new AnnContainer(); AnnRectangleObject rectObj = new AnnRectangleObject(); rectObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel); rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel)); rectObj.Brush = null; container0.Objects.Add(rectObj); // The second container contains a line object AnnContainer container1 = new AnnContainer(); AnnLineObject lineObj = new AnnLineObject(); lineObj.StartPoint = new AnnPoint(100, 100, AnnUnit.Pixel); lineObj.EndPoint = new AnnPoint(200, 200, AnnUnit.Pixel); lineObj.Pen = new AnnPen(Color.Red, new AnnLength(1, AnnUnit.Pixel)); container1.Objects.Add(lineObj); // The third container contains a ellipse object AnnContainer container2 = new AnnContainer(); AnnEllipseObject ellipseObj = new AnnEllipseObject(); ellipseObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel); ellipseObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel)); ellipseObj.Brush = null; container2.Objects.Add(ellipseObj); // create a memory stream to save both annotation containers using (MemoryStream ms = new MemoryStream()) { // create a new AnnCodecs class AnnCodecs codecs = new AnnCodecs(); // save both AnnContainers into the stream codecs.Save(ms, container0, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite); ms.Seek(0, SeekOrigin.Begin); codecs.Save(ms, container1, AnnCodecsFormat.Xml, 2, AnnCodecsSavePageMode.Insert); ms.Seek(0, SeekOrigin.Begin); // Now load both containers from the stream, and verify that there are two containers AnnContainer[] containersTwo = codecs.Load(ms); MessageBox.Show(String.Format("After Load: there should be 2 containers. Total number of containers: {0}", containersTwo.Length)); // Add another container, and save to the stream AnnContainer[] containersNew = new AnnContainer[containersTwo.Length + 1]; Array.Copy(containersTwo, containersNew, containersTwo.Length); containersNew[2] = container2; ms.Seek(0, SeekOrigin.Begin); codecs.Save(ms, containersNew, AnnCodecsFormat.Xml); ms.Seek(0, SeekOrigin.Begin); // Load and verify that there are three containers AnnContainer[] containersThree = codecs.Load(ms); MessageBox.Show(String.Format("After Load: there should be 3 containers. Total number of containers: {0}", containersThree.Length)); } }